package com.yuniarti.konsultasikesehatan;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MenuMemberActivity extends Activity implements OnClickListener {

	public String id;
    TextView namalengkap;
    
	DataParser jParser = new DataParser();
	private static String url_member = "http://konsultasi-yakes.web.id/JSON/menu-member.php";
	//private static String url_member = "http://10.0.2.2/adminweb/JSON/menu-member.php";
	
	private static final String AR_MEMBER = "member";
    private static final String AR_ID = "id_member";
    private static final String AR_NAMA = "namalengkap";
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu_member);
		
		findViewById(R.id.btn_input).setOnClickListener(this);
		findViewById(R.id.btn_hasil).setOnClickListener(this);
		findViewById(R.id.btn_password).setOnClickListener(this);
		
		Intent i = getIntent();
        id = i.getStringExtra(AR_ID);
 
        new GetMember().execute();
	}

	class GetMember extends AsyncTask<String, String, String> {

        protected String doInBackground(String... params) {
 
            runOnUiThread(new Runnable() {
                public void run() {
      
                  //  int success;
                    try {
       
                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("id_member", id));
 
                        JSONObject json = jParser.makeHttpRequest(url_member, "GET", params);
                            JSONArray menuObj = json.getJSONArray(AR_MEMBER); 
                            
                            JSONObject product = menuObj.getJSONObject(0);
 
                            namalengkap= (TextView) findViewById(R.id.tvSalam);
                            namalengkap.setText(product.getString(AR_NAMA));
            
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
 
            return null;
        }
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_input:
			Intent inputintent = new Intent(this,KonsultasiActivity.class);
			inputintent.putExtra(AR_ID, id);
			startActivity(inputintent);
			break;
		case R.id.btn_hasil:
			Intent hasilintent = new Intent(this,HasilActivity.class);
			hasilintent.putExtra(AR_ID, id);
			startActivity(hasilintent);
			break;
		case R.id.btn_password:
			Intent passintent = new Intent(this,PasswordActivity.class);
			passintent.putExtra(AR_ID, id);
			startActivity(passintent);
			break;
		default:
			break;
		}
	}

}
